<!DOCTYPE html>
<html data-bs-theme="light">

<head>
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <meta name="referrer" content="same-origin" />
    <meta name="author" content="Yuan_Tuo" />
    <meta name="author" content="LC" />
    <meta name="version" content="<?= $program_version ?>" />
    <meta name="description" content="PanDownload 网页版，百度网盘分享链接在线解析工具。" />
    <meta name="keywords" content="PanDownload,百度网盘,分享链接,下载,不限速" />
    <title>
        <?= $site_name ?>
    </title>
    <link rel="icon" href="favicon.ico" />
    <link rel="stylesheet" href="static/index.css?v=<?= $program_version ?>" />
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/5.8.1/css/all.min.css" />
    <link rel="stylesheet" href="https://cdn.staticfile.org/bootstrap/5.3.0-alpha2/css/bootstrap.min.css" />
    <link rel="stylesheet" disabled id="Swal2-Dark"
        href="https://fastly.jsdelivr.net/npm/@sweetalert2/theme-dark@4.0.2/dark.min.css" />
    <link rel="stylesheet" disabled id="Swal2-Light"
        href="https://fastly.jsdelivr.net/npm/@sweetalert2/theme-default@4.0.2/default.min.css" />
    <script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>
    <script src="https://cdn.staticfile.org/bootstrap/5.3.0-alpha2/js/bootstrap.bundle.min.js"></script>
    <script src="https://fastly.jsdelivr.net/npm/sweetalert2@10.14.0/dist/sweetalert2.min.js"></script>
    <script src="https://fastly.jsdelivr.net/npm/@keeex/qrcodejs-kx"></script>
    <script src="https://filecxx.com/script/create_filec_address.js"></script>
    <script src="static/color.js?v=<?= $program_version ?>"></script>
    <script src="static/functions.js?v=<?= $program_version ?>"></script>
    <script async="false" src="static/ready.js?v=<?= $program_version ?>"></script>
</head>

<body>
    <nav class="navbar navbar-expand-sm bg-dark navbar-dark">
        <div class="container">
            <a class="navbar-brand" href="./"><img src="resource/logo.png" class="img-fluid rounded logo-img mr-2"
                    alt="LOGO" /> PanDownload</a>
            <button class="navbar-toggler border-0" type="button" data-bs-toggle="collapse"
                data-bs-target="#collpase-bar"><span class="navbar-toggler-icon"></span></button>
            <div class="collapse navbar-collapse" id="collpase-bar">
                <ul class="navbar-nav" style="width: 100%;">
                    <li class="nav-item"><a class="nav-link" href="javascript:navigate('index')">首页</a></li>
                    <li class="nav-item"><a class="nav-link" href="javascript:navigate('help')">使用帮助</a></li>
                    <li class="nav-item"><a class="nav-link" href="javascript:navigate('usersettings')">用户设置</a></li>
                    <li class="nav-item"><a class="nav-link" href="https://github.com/yuantuo666/baiduwp-php"
                            target="_blank">Github</a></li>
                    <li class="nav-item" style="flex-grow: 1;"></li>
                    <li class="nav-item"><a class="nav-link" href="./admin" target="_blank">管理后台</a></li>
                </ul>
            </div>
        </div>
    </nav>
    <div class="container main">
        <div class="col-lg-6 col-md-9 mx-auto mb-5 input-card page" id="index" style="display: none;">
            <div class="card">
                <div class="card-header bg-dark text-light">
                    <text id="parsing_tooltip" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-html="true"
                        data-bs-title="连接中">
                        百度网盘在线解析
                    </text>
                    <span style="float: right;" id="svip_tooltip" data-bs-toggle="tooltip" data-bs-placement="top"
                        data-bs-html="true" data-bs-title="连接中"><span class="point point-lg"
                            id="svip_status-point"></span><span id="svip_status">Loading...</span></span>
                </div>
                <div class="card-body">
                    <div class="form-group my-2"><input type="text" class="form-control" name="surl"
                            placeholder="请输入分享链接(可输入带提取码链接)" oninput="Getpw()"></div>
                    <div class="form-group my-4"><input type="text" class="form-control" name="pwd"
                            placeholder="请输入提取码(没有留空)"></div>
                    <div class="form-group my-4" id="password" style="display: none;"><input type="text"
                            class="form-control" name="password" placeholder="请输入站点密码"></div>
                    <div class="form-group mt-4 mb-3 d-grid">
                        <button onclick="SubmitLink()" class="btn btn-primary">
                            提交
                        </button>
                    </div>
                </div>
            </div>
            <script>
                function checkPassword() {
                    getAPI('/auth/status').then(function (response) {
                        switch (response.data.status) {
                            case 0:
                                // 无密码
                                $("#password").hide();
                                break;
                            case 1:
                                // 有密码
                                $("#password").html(`<input type="text" class="form-control" name="password" placeholder="请输入站点密码">`);
                                $("#password").show();
                                break;
                            case 2:
                                // 密码正确
                                $("#password").html("您的设备在短期内已经验证过，无需再次输入密码。");
                                $("#password").show();
                                break;
                        }
                    });
                }

                // 主页部分脚本
                $(document).ready(function () {
                    // 路由判断
                    let hash = window.location.hash.replace("#", "");
                    if (hash === "/list") {
                        hash = "/index"
                    }
                    navigate(hash)

                    // 获取系统信息
                    getAPI('/system').then(function (response) {
                        if (response.success) {
                            const data = response.data;
                            if (data.error === 114514) {
                                // 未安装
                                Swal.fire({
                                    icon: 'error',
                                    title: '未安装',
                                    text: '即将前往安装页面。'
                                }).then(function () {
                                    window.location.href = `${ROOT_PATH}/install`;
                                });
                            }
                            if (data.error === 1919810) {
                                // 版本不一致
                                Swal.fire({
                                    icon: 'error',
                                    title: '安装版本和代码版本不一致',
                                    text: '需要安装更新，即将前往安装更新页面。'
                                }).then(function () {
                                    window.location.href = `${ROOT_PATH}/install/upgrade`;
                                });
                            }
                            if (data.error === 0) {
                                // 请求成功
                                if (!data.account) {
                                    $("#svip_status").text("未知");
                                    $("#svip_tooltip").attr("data-bs-title", "未启用数据库，无法判断账号状态");
                                } else {
                                    if (data.account.limit === true) {
                                        $("#svip_status").text("限速");
                                        $("#svip_status-point").addClass("point-danger");
                                        $("#svip_tooltip").attr("data-bs-title", `上次解析时间：${data.account.last_time} <br />账号状态：已被限速`);
                                    }
                                    if (data.account.limit === false) {
                                        $("#svip_status").text("正常");
                                        $("#svip_status-point").addClass("point-success");
                                        $("#svip_tooltip").attr("data-bs-title", `上次解析时间：${data.account.last_time} <br />账号状态：正常`);
                                    }
                                    if (data.account.limit === null) {
                                        $("#svip_status").text("未知");
                                        $("#svip_tooltip").attr("data-bs-title", "无法判断账号状态，请解析一个大于 50 MB 的文件。");
                                    }
                                }

                                new bootstrap.Tooltip(document.getElementById('svip_tooltip'));
                                let count = ''
                                if (data.count) {
                                    count = `<br />今日统计：${formatBytes(data.count.today.flow)} (${data.count.today.times})<br />` +
                                        `系统统计：${formatBytes(data.count.all.flow)} (${data.count.all.times})`;
                                } else {
                                    count = `<br />系统未开启数据库统计功能`;
                                }
                                $("#parsing_tooltip").attr("data-bs-title", `服务器状态：正常 <br />PHP版本：${data.version} ${count}`);
                                new bootstrap.Tooltip(document.getElementById('parsing_tooltip'));
                            }
                        } else {
                            // 请求失败
                            Swal.fire({
                                icon: 'error',
                                title: '请求失败',
                                text: response.msg
                            });
                        }
                    });
                });
            </script>
        </div>

        <div id="list" class="page" style="display: none;">
            <nav class="breadcrumb my-4" aria-label="breadcrumb">
                <ol class="breadcrumb my-3" id="dir-list">
                    <li class="breadcrumb-item active">
                        请稍等，正在连接服务器
                    </li>
                </ol>
            </nav>
            <div>
                <ul class="list-group" id="files-list">
                </ul>
            </div>
        </div>

        <div class="modal fade" id="downloadpage" tabindex="-1" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title">
                            获取下载链接成功
                        </h5>
                        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                    </div>
                    <div class="modal-body">
                        <div id="downloadlinkdiv">

                        </div>
                        <h5 class="text-danger" id="limit-tip" style="display: none;">
                            当前 SVIP 账号已被限速，请更换账号。
                        </h5>
                        <p class="card-text">
                            <a class="btn btn-outline-primary" data-bs-toggle="modal" data-bs-target="#SendToAria2">
                                发送到 Aria2 / Motrix
                            </a>
                            <a class="btn btn-outline-primary" href="" id="filecxx" style="display: none;">
                                发送到 文件蜈蚣
                            </a>
                        </p>
                        <p class="card-text"><a class="btn btn-outline-secondary" href="./#/help" target="_blank">
                                下载帮助（必读）
                            </a></p>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">
                            关闭
                        </button>
                    </div>
                </div>
            </div>
        </div>

        <div class="modal fade" id="SendToAria2" tabindex="-1" aria-hidden="true">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title">
                            发送到 Aria2 / Motrix Json-RPC
                        </h5>
                        <button type="button" class="btn-close" data-bs-toggle="modal"
                            data-bs-target="#downloadpage"></button>
                    </div>
                    <div class="modal-body">
                        <div class="form-group">
                            <p><label class="control-label">RPC地址</label>
                                <input id="wsurl" class="form-control" value="ws://localhost:6800/jsonrpc">
                            </p>
                            <small>推送aria2默认配置:<b>ws://localhost:6800/jsonrpc</b><br />推送Motrix默认配置:<b>ws://localhost:16800/jsonrpc</b></small>
                        </div>
                        <div class="form-group">
                            <p><label class="control-label">Token</label>
                                <input id="token" class="form-control" placeholder="没有请留空">
                            </p>
                        </div>
                        <small>填写的信息在推送成功后将会被自动保存。</small>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-primary" onclick="addUri()" data-bs-toggle="modal"
                            data-bs-target="#downloadpage">
                            发送
                        </button>
                        <button type="button" class="btn btn-secondary" data-bs-toggle="modal"
                            data-bs-target="#downloadpage">
                            返回
                        </button>
                    </div>
                </div>
            </div>
            <script>
                $(function () {
                    if (localStorage.getItem('aria2wsurl') !== null)
                        $('#wsurl').attr('value', localStorage.getItem('aria2wsurl'));
                    if (localStorage.getItem('aria2token') !== null)
                        $('#token').attr('value', localStorage.getItem('aria2token'));
                });
            </script>
        </div>

        <div class="card page" id="usersettings" style="display: none;">
            <div class="card-header">
                用户设置
            </div>
            <div class="card-body">
                <div class="card-item">
                    <h3>
                        色彩模式
                    </h3>
                    <div id="ColorMode-Setting-View">
                        <span class="SaveTime">
                            将会永久保存。
                        </span>
                        <span>
                            浏览器设置：
                        </span><span id="Browser-ColorMode"></span>
                        <span>
                            当前设置：
                        </span><span id="Setting-ColorMode"></span>
                    </div>
                    <select id="ColorMode-Select" class="form-control">
                        <option value="auto">
                            跟随浏览器（默认）
                        </option>
                        <option value="dark">
                            深色模式
                        </option>
                        <option value="light">
                            浅色模式
                        </option>
                    </select>
                </div>
                <div class="card-item mt-4">
                    <h3>
                        自动检查更新
                    </h3>
                    <div id="UpdateTips">
                        自动检查更新，有新版本时会在首页显示更新提示。
                    </div>
                    <select id="UpdateTips-Select" class="form-control">
                        <option value="true">
                            启用
                        </option>
                        <option value="false">
                            禁用
                        </option>
                    </select>
                </div>
            </div>
        </div>

        <script>
            if (localStorage.getItem('colorMode') === null) { // 判断用户设置的颜色
                $('#Setting-ColorMode').text('跟随浏览器（默认）'); // 跟随浏览器
                $('#ColorMode-Select option[value=auto]')[0].selected = true;
            } else if (localStorage.getItem('colorMode') === 'dark') { // 深色模式
                $('#Setting-ColorMode').text('深色模式');
                $('#ColorMode-Select option[value=dark]')[0].selected = true;
            } else if (localStorage.getItem('colorMode') === 'light') { // 浅色模式
                $('#Setting-ColorMode').text('浅色模式');
                $('#ColorMode-Select option[value=light]')[0].selected = true;
            }

            const dark = window.matchMedia('(prefers-color-scheme: dark)'),
                light = window.matchMedia('(prefers-color-scheme: light)');

            function changeColorMode() { // 更改颜色模式显示
                if (dark.matches) { // 获取浏览器设置
                    $('#Browser-ColorMode').text('深色模式'); // 深色模式
                } else if (light.matches) { // 获取浏览器设置
                    $('#Browser-ColorMode').text('浅色模式'); // 浅色模式
                }
            }

            dark.addEventListener('change', changeColorMode); // 当色彩模式改变为深色模式
            light.addEventListener('change', changeColorMode); // 当色彩模式改变为浅色模式
            changeColorMode(); // 初始化

            $('#ColorMode-Select').on('change', function () {
                if (this.value === 'auto') {
                    localStorage.removeItem('colorMode');
                } else {
                    localStorage.setItem('colorMode', this.value);
                }
                location.reload();
            });

            // check if the user set the update tip
            let UpdateTip = localStorage.getItem('UpdateTip') || 'true';
            if (UpdateTip === 'true') {
                $('#UpdateTips-Select option[value=true]')[0].selected = true;
            } else {
                $('#UpdateTips-Select option[value=false]')[0].selected = true;
            }

            $('#UpdateTips-Select').on('change', function () {
                if (this.value === 'true') {
                    localStorage.removeItem('UpdateTip');
                } else {
                    localStorage.setItem('UpdateTip', 'false');
                }
                location.reload();
            });
        </script>

        <div id="help" class="page" style="display: none;">
            <div class="row justify-content-center">
                <div class="col-11">
                    <div class="alert alert-primary" role="alert">
                        <h5 class="alert-heading">下载提示</h5>
                        <hr />
                        <p class="card-text">因百度限制，需修改浏览器 User-Agent 后下载。你可以在下方选择你喜欢的方式进行下载。<br />
                        <div class="page-inner">
                            <section class="normal" id="section-">
                                <div id="Motrix"><a class="anchor" href="#Motrix"></a>
                                    <h4>Motrix（推荐）</h4>
                                </div>
                                <ol>
                                    <li>前往 <a href="https://motrix.app/" target="_blank">Motrix官网</a> 下载 <b>Motrix</b>
                                        对应版本</li>
                                    <li>安装后运行Motrix。</li>
                                    <li>打开解析下载页面，点击 <b>推送到 Aria2(Motrix)</b></li>
                                    <li>在“RPC地址”中输入 <b>ws://localhost:16800/jsonrpc</b> 并 点击发送。</li>
                                </ol>
                                <div id="aria2-windows"><a class="anchor" href="#aria2-windows"></a>
                                    <h4>Aria2（Windows）</h4>
                                </div>
                                <ol>
                                    <li><a href="./resource/aria2.zip">点击此处</a> 下载 <b>aria2.zip</b></li>
                                    <li>解压 <b>aria2.zip</b> 文件并运行其中的 <b>点此启动.bat</b></li>
                                    <li>打开解析下载页面，点击 <b>推送到 Aria2(Motrix)</b></li>
                                </ol>
                                <div id="aria2-android"><a class="anchor" href="#aria2-android"></a>
                                    <h4>Aria2（安卓）</h4>
                                </div>
                                <ol>
                                    <li><a data-qrcode-attr="href"
                                            href="https://github.com/devgianlu/Aria2Android/releases/download/v2.6.1/app-foss-release.apk">点击此处</a>
                                        下载 <b>Aria2Android.apk</b></li>
                                    <li>安装并运行 <b>Aria2Android.apk</b></li>
                                    <li>将 RPC -> RPC令牌(token) 设置好后，点击右下角启动 aria2</li>
                                    <li>打开解析下载页面，将上一步设置的 <b>token</b> 输入框中，点击 <b>推送到 Aria2(Motrix)</b></li>
                                </ol>
                                <div id="IDM"><a class="anchor" href="#IDM"></a>
                                    <h4>IDM</h4>
                                </div>
                                <ol>
                                    <li>选项 -> 下载 -> 手动添加任务时使用的用户代理（UA）-> 填入 <b>LogStatistic</b></li>
                                    <li><b>右键复制下载链接</b>（如果 直接点击 或 右键调用IDM 将传入浏览器的 UA 导致下载失败），在 IDM 新建任务，粘贴链接即可下载。</li>
                                </ol>
                                <div id="Chrome"><a class="anchor" href="#Chrome"></a>
                                    <h4>Chrome 浏览器</h4>
                                </div>
                                <ol>
                                    <li>安装浏览器扩展程序 <a
                                            href="https://chrome.google.com/webstore/detail/user-agent-switcher-for-c/djflhoibgkdhkhhcedjiklpkjnoahfmg"
                                            target="_blank">User-Agent Switcher for Chrome</a></li>
                                    <li>右键点击扩展图标 -> 选项</li>
                                    <li>New User-Agent name 填入 百度网盘分享下载</li>
                                    <li>New User-Agent String 填入 <b>LogStatistic</b></li>
                                    <li>Group 填入 百度网盘</li>
                                    <li>Append? 选择 Replace</li>
                                    <li>Indicator Flag 填入 Log，点击 Add 保存</li>
                                    <li>保存后点击扩展图标，出现“百度网盘”，进入并选择“百度网盘分享下载”。</li>
                                </ol>
                                <blockquote>
                                    <p>Chrome 应用商店打不开或者其他 Chromium 内核的浏览器，<a href="resource/UserAgentSwitcher.crx"
                                            target="_blank">请点此下载</a></p>
                                    <p><a href="https://appcenter.browser.qq.com/search/detail?key=User-Agent%20Switcher%20for%20Chrome&amp;id=djflhoibgkdhkhhcedjiklpkjnoahfmg%20&amp;title=User-Agent%20Switcher%20for%20Chrome"
                                            target="_blank">QQ浏览器插件下载</a></p>
                                </blockquote>
                                <div id="Alook"><a class="anchor" href="#Alook"></a>
                                    <h4>Alook 浏览器（IOS）</h4>
                                </div>
                                <ol>
                                    <li>设置 -> 通用设置 -> 浏览器标识 -> 移动版浏览器标识 -> 自定义 -><br />填入 <b>LogStatistic</b></li>
                                </ol>
                                <div id="Copyright"><a class="anchor" href="#Copyright"></a>
                                    <h4>关于此项目</h4>
                                </div>
                                <ol>
                                    <li>本项目与PanDownload无关。</li>
                                    <li>本项目仅以学习为目的，不得用于其他用途。</li>
                                    <li>当前项目版本：
                                        <?= $program_version ?>
                                    </li>
                                    <li><a href="https://github.com/yuantuo666/baiduwp-php" target="_blank">Github仓库</a>
                                    </li>
                                    <li>项目作者：<a href="https://imwcr.cn/" target="_blank">Yuan_Tuo</a></li>
                                    <li>项目协作者：<a href="https://lcwebsite.cn/" target="_blank">LC</a></li>
                                </ol>
                            </section>
                            <script>
                                $(".anchor").attr("target", "_self").prepend(`<svg viewBox="0 0 16 16" version="1.1" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5
                                    3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"/></svg>`);
                            </script>
                        </div>
                        </p>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div style="position: fixed; bottom: 5px; left: 5px;">
        <?=$footer?>
    </div>
</body>

</html>